{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "f3b4d23b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "\n",
    "# 加载图像\n",
    "image = cv2.imread(r'D:\\test\\Pic.png')\n",
    "\n",
    "# 转换为灰度图\n",
    "gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)\n",
    "\n",
    "# 应用二值化处理\n",
    "_, binary_image = cv2.threshold(gray, 150, 255, cv2.THRESH_BINARY)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "b516e9e5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Collecting paddlepaddle\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7c/0c/6b34944b28576f80f50b191a7a6d70e74acaa8af5eb97a242fc9b033ad8b/paddlepaddle-2.5.2-cp37-cp37m-win_amd64.whl (72.0 MB)\n",
      "     ---------------------------------------- 72.0/72.0 MB 9.0 MB/s eta 0:00:00\n",
      "Collecting httpx (from paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ec/91/e41f64f03d2a13aee7e8c819d82ee3aa7cdc484d18c0ae859742597d5aa0/httpx-0.24.1-py3-none-any.whl (75 kB)\n",
      "     ---------------------------------------- 75.4/75.4 kB ? eta 0:00:00\n",
      "Collecting numpy>=1.13 (from paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/97/9f/da37cc4a188a1d5d203d65ab28d6504e17594b5342e0c1dc5610ee6f4535/numpy-1.21.6-cp37-cp37m-win_amd64.whl (14.0 MB)\n",
      "     --------------------------------------- 14.0/14.0 MB 11.3 MB/s eta 0:00:00\n",
      "Collecting Pillow (from paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/cb/3c/4f3ef1a14e903d7b2bc43672c20f732b874e1e50a9a58ac9a1726ef3773d/Pillow-9.5.0-cp37-cp37m-win_amd64.whl (2.5 MB)\n",
      "     ---------------------------------------- 2.5/2.5 MB 9.5 MB/s eta 0:00:00\n",
      "Requirement already satisfied: decorator in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from paddlepaddle) (5.1.1)\n",
      "Collecting astor (from paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/c3/88/97eef84f48fa04fbd6750e62dcceafba6c63c81b7ac1420856c8dcc0a3f9/astor-0.8.1-py2.py3-none-any.whl (27 kB)\n",
      "Collecting opt-einsum==3.3.0 (from paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/bc/19/404708a7e54ad2798907210462fd950c3442ea51acc8790f3da48d2bee8b/opt_einsum-3.3.0-py3-none-any.whl (65 kB)\n",
      "     ---------------------------------------- 65.5/65.5 kB ? eta 0:00:00\n",
      "Collecting protobuf<=3.20.2,>=3.1.0 (from paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/27/b1/e40edfab7d4ba7f045d94bdf19705056d7c624902976aa2e4341d3cabb06/protobuf-3.20.2-cp37-cp37m-win_amd64.whl (905 kB)\n",
      "     ------------------------------------- 905.1/905.1 kB 11.5 MB/s eta 0:00:00\n",
      "Collecting certifi (from httpx->paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a5/32/8f6669fc4798494966bf446c8c4a162e0b5d893dff088afddf76414f70e1/certifi-2024.12.14-py3-none-any.whl (164 kB)\n",
      "     -------------------------------------- 164.9/164.9 kB 9.7 MB/s eta 0:00:00\n",
      "Collecting httpcore<0.18.0,>=0.15.0 (from httpx->paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/94/2c/2bde7ff8dd2064395555220cbf7cba79991172bf5315a07eb3ac7688d9f1/httpcore-0.17.3-py3-none-any.whl (74 kB)\n",
      "     ---------------------------------------- 74.5/74.5 kB ? eta 0:00:00\n",
      "Collecting idna (from httpx->paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/76/c6/c88e154df9c4e1a2a66ccf0005a88dfb2650c1dffb6f5ce603dfbd452ce3/idna-3.10-py3-none-any.whl (70 kB)\n",
      "     ---------------------------------------- 70.4/70.4 kB ? eta 0:00:00\n",
      "Collecting sniffio (from httpx->paddlepaddle)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e9/44/75a9c9421471a6c4805dbf2356f7c181a29c1879239abab1ea2cc8f38b40/sniffio-1.3.1-py3-none-any.whl (10 kB)\n",
      "Collecting h11<0.15,>=0.13 (from httpcore<0.18.0,>=0.15.0->httpx->paddlepaddle)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/95/04/ff642e65ad6b90db43e668d70ffb6736436c7ce41fcc549f4e9472234127/h11-0.14.0-py3-none-any.whl (58 kB)\n",
      "Collecting anyio<5.0,>=3.0 (from httpcore<0.18.0,>=0.15.0->httpx->paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/19/24/44299477fe7dcc9cb58d0a57d5a7588d6af2ff403fdd2d47a246c91a3246/anyio-3.7.1-py3-none-any.whl (80 kB)\n",
      "     ---------------------------------------- 80.9/80.9 kB ? eta 0:00:00\n",
      "Collecting exceptiongroup (from anyio<5.0,>=3.0->httpcore<0.18.0,>=0.15.0->httpx->paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/02/cc/b7e31358aac6ed1ef2bb790a9746ac2c69bcb3c8588b41616914eb106eaf/exceptiongroup-1.2.2-py3-none-any.whl (16 kB)\n",
      "Collecting typing-extensions (from anyio<5.0,>=3.0->httpcore<0.18.0,>=0.15.0->httpx->paddlepaddle)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ec/6b/63cc3df74987c36fe26157ee12e09e8f9db4de771e0f3404263117e75b95/typing_extensions-4.7.1-py3-none-any.whl (33 kB)\n",
      "Installing collected packages: typing-extensions, sniffio, protobuf, Pillow, numpy, idna, exceptiongroup, certifi, astor, opt-einsum, h11, anyio, httpcore, httpx, paddlepaddle\n",
      "Successfully installed Pillow-9.5.0 anyio-3.7.1 astor-0.8.1 certifi-2024.12.14 exceptiongroup-1.2.2 h11-0.14.0 httpcore-0.17.3 httpx-0.24.1 idna-3.10 numpy-1.21.6 opt-einsum-3.3.0 paddlepaddle-2.5.2 protobuf-3.20.2 sniffio-1.3.1 typing-extensions-4.7.1\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install paddlepaddle"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "0293b8e0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple\n",
      "Collecting paddleocr\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f2/55/0469ebca1d9c581a3fa740621afe96461a0ef450e489e10e278cc17a19ef/paddleocr-2.7.3-py3-none-any.whl (780 kB)\n",
      "     -------------------------------------- 780.0/780.0 kB 2.1 MB/s eta 0:00:00\n",
      "Collecting shapely (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/19/41/40aa902cf93445ecefea2d1735aa07b837c8dceefd6fc70f206898803d28/shapely-2.0.6-cp37-cp37m-win_amd64.whl (1.5 MB)\n",
      "     ---------------------------------------- 1.5/1.5 MB 10.3 MB/s eta 0:00:00\n",
      "Collecting scikit-image (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/10/1c/a35217c9e918bbf9ac8cbb3d2a604f552b14851a97d3fb2282e34b7a8d7d/scikit_image-0.19.3-cp37-cp37m-win_amd64.whl (12.1 MB)\n",
      "     --------------------------------------- 12.1/12.1 MB 10.6 MB/s eta 0:00:00\n",
      "Collecting imgaug (from paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/66/b1/af3142c4a85cba6da9f4ebb5ff4e21e2616309552caca5e8acefe9840622/imgaug-0.4.0-py2.py3-none-any.whl (948 kB)\n",
      "Collecting pyclipper (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5e/21/2a7b0ce60bb267b1d7ac93204a9a5e37fe90caed070998a7d55833d07f6b/pyclipper-1.3.0.post6-cp37-cp37m-win_amd64.whl (110 kB)\n",
      "     ---------------------------------------- 110.9/110.9 kB ? eta 0:00:00\n",
      "Collecting lmdb (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/27/94/9ec2507e35faa227e13235cf2b0611cfb834ed82659f2fc60fe6a28be364/lmdb-1.5.1-cp37-cp37m-win_amd64.whl (105 kB)\n",
      "     -------------------------------------- 105.3/105.3 kB 6.3 MB/s eta 0:00:00\n",
      "Collecting tqdm (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d0/30/dc54f88dd4a2b5dc8a0279bdd7270e735851848b762aeb1c1184ed1f6b14/tqdm-4.67.1-py3-none-any.whl (78 kB)\n",
      "     ---------------------------------------- 78.5/78.5 kB ? eta 0:00:00\n",
      "Requirement already satisfied: numpy in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from paddleocr) (1.21.6)\n",
      "Collecting visualdl (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ea/b5/37726c750a4f4598660998327c3566b2d2ed5a1a5f44e9f0dde875602447/visualdl-2.5.3-py3-none-any.whl (6.3 MB)\n",
      "     ---------------------------------------- 6.3/6.3 MB 11.5 MB/s eta 0:00:00\n",
      "Collecting rapidfuzz (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a3/6b/50a8e1cc04eb525a17b9e229ef68d536c875d754e784917981dc25afe2a1/rapidfuzz-3.4.0-cp37-cp37m-win_amd64.whl (1.8 MB)\n",
      "     ---------------------------------------- 1.8/1.8 MB 7.2 MB/s eta 0:00:00\n",
      "Collecting opencv-python<=4.6.0.66 (from paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/cf/09/b24c266cd61ddeed101b90c92a26f54d060b06f4a1b102eb891576d6e9e2/opencv_python-4.6.0.66-cp36-abi3-win_amd64.whl (35.6 MB)\n",
      "Collecting opencv-contrib-python<=4.6.0.66 (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/63/0b/6ef1acbaa21e5245c85a42f9f0ecfaf2e7420b24615a00f0eee170328e6b/opencv_contrib_python-4.6.0.66-cp36-abi3-win_amd64.whl (42.5 MB)\n",
      "     ---------------------------------------- 42.5/42.5 MB 9.9 MB/s eta 0:00:00\n",
      "Collecting cython (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/31/3b/db8c7867df600f6ef6a9231eba46e20cb9881e80d39a4af884e2302229ed/Cython-3.0.11-cp37-cp37m-win_amd64.whl (2.7 MB)\n",
      "     ---------------------------------------- 2.7/2.7 MB 10.9 MB/s eta 0:00:00\n",
      "Collecting lxml (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/36/55/f661a8a96b7bf890798dc109e0c33849565dcfa3ec32762193e332bac816/lxml-5.3.0-cp37-cp37m-win_amd64.whl (3.8 MB)\n",
      "     ---------------------------------------- 3.8/3.8 MB 11.5 MB/s eta 0:00:00\n",
      "Collecting premailer (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b1/07/4e8d94f94c7d41ca5ddf8a9695ad87b888104e2fd41a35546c1dc9ca74ac/premailer-3.10.0-py2.py3-none-any.whl (19 kB)\n",
      "Collecting openpyxl (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/58/d9/796181a30827b12101786c21301f0f4536597a9249530916b1fdb5bbad91/openpyxl-3.1.3-py2.py3-none-any.whl (251 kB)\n",
      "     ------------------------------------- 251.3/251.3 kB 16.1 MB/s eta 0:00:00\n",
      "Collecting attrdict (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ef/97/28fe7e68bc7adfce67d4339756e85e9fcf3c6fd7f0c0781695352b70472c/attrdict-2.0.1-py2.py3-none-any.whl (9.9 kB)\n",
      "INFO: pip is looking at multiple versions of paddleocr to determine which version is compatible with other requirements. This could take a while.\n",
      "Collecting paddleocr\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f4/2a/50eeffd2786eef1add72a3fd0a33066c99d3b3837f87d51a336cff569020/paddleocr-2.7.2-py3-none-any.whl (780 kB)\n",
      "     -------------------------------------- 780.0/780.0 kB 7.0 MB/s eta 0:00:00\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/8f/d0/1a2f9430f61781beb16556182baa938e8f93c8b46c27ad5865a5655fae05/paddleocr-2.7.0.3-py3-none-any.whl (465 kB)\n",
      "     -------------------------------------- 465.7/465.7 kB 2.6 MB/s eta 0:00:00\n",
      "Collecting PyMuPDF<1.21.0 (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/2a/90/13d45eb3e41232843939840a5d42670db159a4c8d9de46db1ebcdc22ba74/PyMuPDF-1.20.2-cp37-cp37m-win_amd64.whl (6.6 MB)\n",
      "     ---------------------------------------- 6.6/6.6 MB 11.1 MB/s eta 0:00:00\n",
      "Collecting paddleocr\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/30/ba/4bbe3fa30019f70bc864374e957cb4b03844c5c5f0e36b591b439a45b5cb/paddleocr-2.7.0.2-py3-none-any.whl (466 kB)\n",
      "     ------------------------------------- 466.1/466.1 kB 14.7 MB/s eta 0:00:00\n",
      "Requirement already satisfied: Pillow in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from paddleocr) (9.5.0)\n",
      "Collecting python-docx (from paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/3e/3d/330d9efbdb816d3f60bf2ad92f05e1708e4a1b9abe80461ac3444c83f749/python_docx-1.1.2-py3-none-any.whl (244 kB)\n",
      "Collecting beautifulsoup4 (from paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/b1/fe/e8c672695b37eecc5cbf43e1d0638d88d66ba3a44c4d321c796f4e59167f/beautifulsoup4-4.12.3-py3-none-any.whl (147 kB)\n",
      "Collecting fonttools>=4.24.0 (from paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/e3/d9/e9bae85e84737e76ebbcbea13607236da0c0699baed0ae4f1151b728a608/fonttools-4.38.0-py3-none-any.whl (965 kB)\n",
      "Collecting fire>=0.3.0 (from paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/6b/b6/82c7e601d6d3c3278c40b7bd35e17e82aa227f050aa9f66cb7b7fce29471/fire-0.7.0.tar.gz (87 kB)\n",
      "  Preparing metadata (setup.py): started\n",
      "  Preparing metadata (setup.py): finished with status 'done'\n",
      "Collecting pdf2docx (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b5/f9/6d567df395c0409baf2b4dd9cd30d1e977c70672fe7ec2a684af1e6aa41c/pdf2docx-0.5.8-py3-none-any.whl (132 kB)\n",
      "     -------------------------------------- 132.0/132.0 kB 7.6 MB/s eta 0:00:00\n",
      "Collecting termcolor (from fire>=0.3.0->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/67/e1/434566ffce04448192369c1a282931cf4ae593e91907558eaecd2e9f2801/termcolor-2.3.0-py3-none-any.whl (6.9 kB)\n",
      "Requirement already satisfied: six in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from attrdict->paddleocr) (1.16.0)\n",
      "Collecting soupsieve>1.2 (from beautifulsoup4->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/49/37/673d6490efc51ec46d198c75903d99de59baffdd47aea3d071b80a9e4e89/soupsieve-2.4.1-py3-none-any.whl (36 kB)\n",
      "Collecting scipy (from imgaug->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/40/69/4af412d078cef2298f7d90546fa0e03e65a032558bd85319239c72ae0c3c/scipy-1.7.3-cp37-cp37m-win_amd64.whl (34.1 MB)\n",
      "     --------------------------------------- 34.1/34.1 MB 10.4 MB/s eta 0:00:00\n",
      "Collecting matplotlib (from imgaug->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/df/3f/6093a23565d0f50ce433f56223fcc34af6c912cd4331dc582ba29d9b5a17/matplotlib-3.5.3-cp37-cp37m-win_amd64.whl (7.2 MB)\n",
      "     ---------------------------------------- 7.2/7.2 MB 10.7 MB/s eta 0:00:00\n",
      "Collecting imageio (from imgaug->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7b/88/59411e1a652ac3338d348901ffa5a73daf1f67fcb3f97d750237d4fa0821/imageio-2.31.2-py3-none-any.whl (313 kB)\n",
      "     -------------------------------------- 313.2/313.2 kB 9.8 MB/s eta 0:00:00\n",
      "Collecting networkx>=2.2 (from scikit-image->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e9/93/aa6613aa70d6eb4868e667068b5a11feca9645498fd31b954b6c4bb82fa5/networkx-2.6.3-py3-none-any.whl (1.9 MB)\n",
      "     ---------------------------------------- 1.9/1.9 MB 11.1 MB/s eta 0:00:00\n",
      "Collecting tifffile>=2019.7.26 (from scikit-image->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d8/38/85ae5ed77598ca90558c17a2f79ddaba33173b31cf8d8f545d34d9134f0d/tifffile-2021.11.2-py3-none-any.whl (178 kB)\n",
      "     ------------------------------------- 178.9/178.9 kB 11.2 MB/s eta 0:00:00\n",
      "Collecting PyWavelets>=1.1.1 (from scikit-image->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7c/0c/89dea7fed4a6cd3e6f5ade93c7d645a2991a0483916f161a9d72a0d817f8/PyWavelets-1.3.0-cp37-cp37m-win_amd64.whl (4.2 MB)\n",
      "     ---------------------------------------- 4.2/4.2 MB 11.5 MB/s eta 0:00:00\n",
      "Requirement already satisfied: packaging>=20.0 in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from scikit-image->paddleocr) (23.1)\n",
      "Collecting et-xmlfile (from openpyxl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/96/c2/3dd434b0108730014f1b96fd286040dc3bcb70066346f7e01ec2ac95865f/et_xmlfile-1.1.0-py3-none-any.whl (4.7 kB)\n",
      "Collecting opencv-python-headless>=4.5 (from pdf2docx->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/26/d0/22f68eb23eea053a31655960f133c0be9726c6a881547e6e9e7e2a946c4f/opencv_python_headless-4.10.0.84-cp37-abi3-win_amd64.whl (38.8 MB)\n",
      "INFO: pip is looking at multiple versions of python-docx to determine which version is compatible with other requirements. This could take a while.\n",
      "Collecting python-docx (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/4f/b2/771a3410aac134718109e78ed425b0481cfa7a53877ed2f87c0745e6da1a/python_docx-1.1.1-py3-none-any.whl (242 kB)\n",
      "     ------------------------------------- 242.8/242.8 kB 14.5 MB/s eta 0:00:00\n",
      "Collecting lxml (from paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/20/5b/caca461e172d696b151e50a182c6111d192175571e34f483a477122c5d79/lxml-4.9.2-cp37-cp37m-win_amd64.whl (3.8 MB)\n",
      "     ---------------------------------------- 3.8/3.8 MB 11.2 MB/s eta 0:00:00\n",
      "Collecting python-docx (from paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5f/d8/6948f7ac00edf74bfa52b3c5e3073df20284bec1db466d13e668fe991707/python_docx-1.1.0-py3-none-any.whl (239 kB)\n",
      "Requirement already satisfied: typing-extensions in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from python-docx->paddleocr) (4.7.1)\n",
      "Collecting cssselect (from premailer->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/06/a9/2da08717a6862c48f1d61ef957a7bba171e7eefa6c0aa0ceb96a140c2a6b/cssselect-1.2.0-py2.py3-none-any.whl (18 kB)\n",
      "Collecting cssutils (from premailer->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/7a/4a/acc05aba9edb75bf016d9f57928f0bea5a33de2079fd09ca61baec79a6f2/cssutils-2.7.1-py3-none-any.whl (399 kB)\n",
      "     ------------------------------------- 399.7/399.7 kB 12.2 MB/s eta 0:00:00\n",
      "Collecting requests (from premailer->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/70/8e/0e2d847013cb52cd35b38c009bb167a1a26b2ce6cd6965bf26b47bc0bf44/requests-2.31.0-py3-none-any.whl (62 kB)\n",
      "Collecting cachetools (from premailer->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/a4/07/14f8ad37f2d12a5ce41206c21820d8cb6561b728e51fad4530dff0552a67/cachetools-5.5.0-py3-none-any.whl (9.5 kB)\n",
      "Requirement already satisfied: colorama in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from tqdm->paddleocr) (0.4.6)\n",
      "Collecting bce-python-sdk (from visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/f4/f9/3e68f4bc1798bb260faff98af3d20b13572318effda1a77faac75ded0bff/bce_python_sdk-0.9.23-py3-none-any.whl (336 kB)\n",
      "     ------------------------------------- 336.7/336.7 kB 10.5 MB/s eta 0:00:00\n",
      "Collecting flask>=1.1.1 (from visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/9f/1a/8b6d48162861009d1e017a9740431c78d860809773b66cac220a11aa3310/Flask-2.2.5-py3-none-any.whl (101 kB)\n",
      "     -------------------------------------- 101.8/101.8 kB 5.7 MB/s eta 0:00:00\n",
      "Collecting Flask-Babel>=3.0.0 (from visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5e/b2/ec77c54dcc31acef7fb75c5730f35714ab4fe4742b41d99fc932eefe6ca1/flask_babel-3.1.0-py3-none-any.whl (9.6 kB)\n",
      "Requirement already satisfied: protobuf>=3.20.0 in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from visualdl->paddleocr) (3.20.2)\n",
      "Collecting pandas (from visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b2/56/f886ed6f1777ffa9d54c6e80231b69db8a1f52dcc33f5967b06a105dcfe0/pandas-1.3.5-cp37-cp37m-win_amd64.whl (10.0 MB)\n",
      "     ---------------------------------------- 10.0/10.0 MB 8.7 MB/s eta 0:00:00\n",
      "Collecting rarfile (from visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/62/fc/ab37559419ca36dd8dd317c3a98395ed4dcee2beeb28bf6059b972906727/rarfile-4.2-py3-none-any.whl (29 kB)\n",
      "Requirement already satisfied: psutil in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from visualdl->paddleocr) (5.9.3)\n",
      "Collecting Werkzeug>=2.2.2 (from flask>=1.1.1->visualdl->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/f6/f8/9da63c1617ae2a1dec2fbf6412f3a0cfe9d4ce029eccbda6e1e4258ca45f/Werkzeug-2.2.3-py3-none-any.whl (233 kB)\n",
      "Collecting Jinja2>=3.0 (from flask>=1.1.1->visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/31/80/3a54838c3fb461f6fec263ebf3a3a41771bd05190238de3486aae8540c36/jinja2-3.1.4-py3-none-any.whl (133 kB)\n",
      "     -------------------------------------- 133.3/133.3 kB 7.7 MB/s eta 0:00:00\n",
      "Collecting itsdangerous>=2.0 (from flask>=1.1.1->visualdl->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/68/5f/447e04e828f47465eeab35b5d408b7ebaaaee207f48b7136c5a7267a30ae/itsdangerous-2.1.2-py3-none-any.whl (15 kB)\n",
      "Collecting click>=8.0 (from flask>=1.1.1->visualdl->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/00/2e/d53fa4befbf2cfa713304affc7ca780ce4fc1fd8710527771b58311a3229/click-8.1.7-py3-none-any.whl (97 kB)\n",
      "Collecting importlib-metadata>=3.6.0 (from flask>=1.1.1->visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/ff/94/64287b38c7de4c90683630338cf28f129decbba0a44f0c6db35a873c73c4/importlib_metadata-6.7.0-py3-none-any.whl (22 kB)\n",
      "Collecting Babel>=2.12 (from Flask-Babel>=3.0.0->visualdl->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/0d/35/4196b21041e29a42dc4f05866d0c94fa26c9da88ce12c38c2265e42c82fb/Babel-2.14.0-py3-none-any.whl (11.0 MB)\n",
      "Collecting pytz>=2022.7 (from Flask-Babel>=3.0.0->visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/11/c3/005fcca25ce078d2cc29fd559379817424e94885510568bc1bc53d7d5846/pytz-2024.2-py2.py3-none-any.whl (508 kB)\n",
      "     ------------------------------------- 508.0/508.0 kB 10.6 MB/s eta 0:00:00\n",
      "Collecting pycryptodome>=3.8.0 (from bce-python-sdk->visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/43/1d/81d59d228381576b92ecede5cd7239762c14001a828bdba30d64896e9778/pycryptodome-3.21.0-cp36-abi3-win_amd64.whl (1.8 MB)\n",
      "     ---------------------------------------- 1.8/1.8 MB 11.6 MB/s eta 0:00:00\n",
      "Collecting future>=0.6.0 (from bce-python-sdk->visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/da/71/ae30dadffc90b9006d77af76b393cb9dfbfc9629f339fc1574a1c52e6806/future-1.0.0-py3-none-any.whl (491 kB)\n",
      "     ------------------------------------- 491.3/491.3 kB 10.2 MB/s eta 0:00:00\n",
      "Collecting cycler>=0.10 (from matplotlib->imgaug->paddleocr)\n",
      "  Using cached https://pypi.tuna.tsinghua.edu.cn/packages/5c/f9/695d6bedebd747e5eb0fe8fad57b72fdf25411273a39791cde838d5a8f51/cycler-0.11.0-py3-none-any.whl (6.4 kB)\n",
      "Collecting kiwisolver>=1.0.1 (from matplotlib->imgaug->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/27/b5/c548a1f1cef3fb9af3f59d6fc4259aa17c48403680c33435ca675aae2b30/kiwisolver-1.4.5-cp37-cp37m-win_amd64.whl (55 kB)\n",
      "     ---------------------------------------- 55.8/55.8 kB 3.0 MB/s eta 0:00:00\n",
      "Collecting pyparsing>=2.2.1 (from matplotlib->imgaug->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/e5/0c/0e3c05b1c87bb6a1c76d281b0f35e78d2d80ac91b5f8f524cebf77f51049/pyparsing-3.1.4-py3-none-any.whl (104 kB)\n",
      "     ---------------------------------------- 104.1/104.1 kB ? eta 0:00:00\n",
      "Requirement already satisfied: python-dateutil>=2.7 in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from matplotlib->imgaug->paddleocr) (2.8.2)\n",
      "Collecting charset-normalizer<4,>=2 (from requests->premailer->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/b6/33/cf8f2602715863219804c1790374b611f08be515176229de078f807d71e3/charset_normalizer-3.4.0-cp37-cp37m-win_amd64.whl (99 kB)\n",
      "     ---------------------------------------- 99.9/99.9 kB ? eta 0:00:00\n",
      "Requirement already satisfied: idna<4,>=2.5 in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from requests->premailer->paddleocr) (3.10)\n",
      "Collecting urllib3<3,>=1.21.1 (from requests->premailer->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/d2/b2/b157855192a68541a91ba7b2bbcb91f1b4faa51f8bae38d8005c034be524/urllib3-2.0.7-py3-none-any.whl (124 kB)\n",
      "     -------------------------------------- 124.2/124.2 kB 3.7 MB/s eta 0:00:00\n",
      "Requirement already satisfied: certifi>=2017.4.17 in d:\\programdata\\anaconda3\\envs\\py37\\lib\\site-packages (from requests->premailer->paddleocr) (2024.12.14)\n",
      "Collecting zipp>=0.5 (from importlib-metadata>=3.6.0->flask>=1.1.1->visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/5b/fa/c9e82bbe1af6266adf08afb563905eb87cab83fde00a0a08963510621047/zipp-3.15.0-py3-none-any.whl (6.8 kB)\n",
      "Collecting MarkupSafe>=2.0 (from Jinja2>=3.0->flask>=1.1.1->visualdl->paddleocr)\n",
      "  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/6c/4c/3577a52eea1880538c435176bc85e5b3379b7ab442327ccd82118550758f/MarkupSafe-2.1.5-cp37-cp37m-win_amd64.whl (17 kB)\n",
      "Building wheels for collected packages: fire\n",
      "  Building wheel for fire (setup.py): started\n",
      "  Building wheel for fire (setup.py): finished with status 'done'\n",
      "  Created wheel for fire: filename=fire-0.7.0-py3-none-any.whl size=114262 sha256=7954848424681d6c1a106e881de38572806a5467d5ba7f7e376e36e3bc9a6a21\n",
      "  Stored in directory: c:\\users\\shan\\appdata\\local\\pip\\cache\\wheels\\19\\6b\\cf\\5ef807ebf081452a4b7ba8c98e205d53569fef2a427583c51e\n",
      "Successfully built fire\n",
      "Installing collected packages: pytz, pyclipper, lmdb, zipp, urllib3, tqdm, tifffile, termcolor, soupsieve, shapely, scipy, rarfile, rapidfuzz, PyWavelets, pyparsing, PyMuPDF, pycryptodome, opencv-python-headless, opencv-python, opencv-contrib-python, networkx, MarkupSafe, lxml, kiwisolver, itsdangerous, imageio, future, fonttools, et-xmlfile, cython, cycler, cssselect, charset-normalizer, cachetools, Babel, attrdict, Werkzeug, scikit-image, requests, python-docx, pandas, openpyxl, matplotlib, Jinja2, importlib-metadata, fire, beautifulsoup4, bce-python-sdk, pdf2docx, imgaug, cssutils, click, premailer, flask, Flask-Babel, visualdl, paddleocr\n",
      "Successfully installed Babel-2.14.0 Flask-Babel-3.1.0 Jinja2-3.1.4 MarkupSafe-2.1.5 PyMuPDF-1.20.2 PyWavelets-1.3.0 Werkzeug-2.2.3 attrdict-2.0.1 bce-python-sdk-0.9.23 beautifulsoup4-4.12.3 cachetools-5.5.0 charset-normalizer-3.4.0 click-8.1.7 cssselect-1.2.0 cssutils-2.7.1 cycler-0.11.0 cython-3.0.11 et-xmlfile-1.1.0 fire-0.7.0 flask-2.2.5 fonttools-4.38.0 future-1.0.0 imageio-2.31.2 imgaug-0.4.0 importlib-metadata-6.7.0 itsdangerous-2.1.2 kiwisolver-1.4.5 lmdb-1.5.1 lxml-5.3.0 matplotlib-3.5.3 networkx-2.6.3 opencv-contrib-python-4.6.0.66 opencv-python-4.6.0.66 opencv-python-headless-4.10.0.84 openpyxl-3.1.3 paddleocr-2.7.0.2 pandas-1.3.5 pdf2docx-0.5.8 premailer-3.10.0 pyclipper-1.3.0.post6 pycryptodome-3.21.0 pyparsing-3.1.4 python-docx-1.1.0 pytz-2024.2 rapidfuzz-3.4.0 rarfile-4.2 requests-2.31.0 scikit-image-0.19.3 scipy-1.7.3 shapely-2.0.6 soupsieve-2.4.1 termcolor-2.3.0 tifffile-2021.11.2 tqdm-4.67.1 urllib3-2.0.7 visualdl-2.5.3 zipp-3.15.0\n",
      "Note: you may need to restart the kernel to use updated packages.\n"
     ]
    }
   ],
   "source": [
    "pip install paddleocr"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "253ef18c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[2024/12/15 17:39:02] ppocr DEBUG: Namespace(alpha=1.0, benchmark=False, beta=1.0, cls_batch_num=6, cls_image_shape='3, 48, 192', cls_model_dir='C:\\\\Users\\\\Shan/.paddleocr/whl\\\\cls\\\\ch_ppocr_mobile_v2.0_cls_infer', cls_thresh=0.9, cpu_threads=10, crop_res_save_dir='./output', det=True, det_algorithm='DB', det_box_type='quad', det_db_box_thresh=0.6, det_db_score_mode='fast', det_db_thresh=0.3, det_db_unclip_ratio=1.5, det_east_cover_thresh=0.1, det_east_nms_thresh=0.2, det_east_score_thresh=0.8, det_limit_side_len=960, det_limit_type='max', det_model_dir='C:\\\\Users\\\\Shan/.paddleocr/whl\\\\det\\\\ch\\\\ch_PP-OCRv4_det_infer', det_pse_box_thresh=0.85, det_pse_min_area=16, det_pse_scale=1, det_pse_thresh=0, det_sast_nms_thresh=0.2, det_sast_score_thresh=0.5, draw_img_save_dir='./inference_results', drop_score=0.5, e2e_algorithm='PGNet', e2e_char_dict_path='./ppocr/utils/ic15_dict.txt', e2e_limit_side_len=768, e2e_limit_type='max', e2e_model_dir=None, e2e_pgnet_mode='fast', e2e_pgnet_score_thresh=0.5, e2e_pgnet_valid_set='totaltext', enable_mkldnn=False, fourier_degree=5, gpu_id=0, gpu_mem=500, help='==SUPPRESS==', image_dir=None, image_orientation=False, ir_optim=True, kie_algorithm='LayoutXLM', label_list=['0', '180'], lang='ch', layout=True, layout_dict_path=None, layout_model_dir=None, layout_nms_threshold=0.5, layout_score_threshold=0.5, max_batch_size=10, max_text_length=25, merge_no_span_structure=True, min_subgraph_size=15, mode='structure', ocr=True, ocr_order_method=None, ocr_version='PP-OCRv4', output='./output', page_num=0, precision='fp32', process_id=0, re_model_dir=None, rec=True, rec_algorithm='SVTR_LCNet', rec_batch_num=6, rec_char_dict_path='D:\\\\ProgramData\\\\Anaconda3\\\\envs\\\\py37\\\\lib\\\\site-packages\\\\paddleocr\\\\ppocr\\\\utils\\\\ppocr_keys_v1.txt', rec_image_inverse=True, rec_image_shape='3, 48, 320', rec_model_dir='C:\\\\Users\\\\Shan/.paddleocr/whl\\\\rec\\\\ch\\\\ch_PP-OCRv4_rec_infer', recovery=False, return_word_box=False, save_crop_res=False, save_log_path='./log_output/', scales=[8, 16, 32], ser_dict_path='../train_data/XFUND/class_list_xfun.txt', ser_model_dir=None, show_log=True, sr_batch_num=1, sr_image_shape='3, 32, 128', sr_model_dir=None, structure_version='PP-StructureV2', table=True, table_algorithm='TableAttn', table_char_dict_path=None, table_max_len=488, table_model_dir=None, total_process_num=1, type='ocr', use_angle_cls=True, use_dilation=False, use_gpu=False, use_mp=False, use_npu=False, use_onnx=False, use_pdf2docx_api=False, use_pdserving=False, use_space_char=True, use_tensorrt=False, use_visual_backbone=True, use_xpu=False, vis_font_path='./doc/fonts/simfang.ttf', warmup=False)\n",
      "[2024/12/15 17:39:04] ppocr DEBUG: dt_boxes num : 29, elapse : 0.999176025390625\n",
      "[2024/12/15 17:39:04] ppocr DEBUG: cls num  : 29, elapse : 0.3651463985443115\n",
      "[2024/12/15 17:39:10] ppocr DEBUG: rec_res num  : 29, elapse : 5.877951383590698\n",
      "查看报名信息\n",
      "考生姓名：\n",
      "韦善宁\n",
      "证件号码：\n",
      "452728200006221514\n",
      "报名序号：\n",
      "202502566269\n",
      "性别：\n",
      "男\n",
      "考区:\n",
      "广西壮族自治区\n",
      "考点城市：\n",
      "南宁市1\n",
      "考试类别:\n",
      "市（地）级及以下直属机构综合管理类\n",
      "报考部门代码：\n",
      "132120\n",
      "报考部门：\n",
      "国家金融监督管理总局广西监管局\n",
      "报考职位代码：\n",
      "300147567001\n",
      "报考职位：\n",
      "综合部门一级主任科员及以下\n",
      "职位属性：\n",
      "金融监管计算机类职位\n",
      "缴费状态：\n",
      "已缴费\n",
      "照片审核状态：\n",
      "审核已通过\n"
     ]
    }
   ],
   "source": [
    "from paddleocr import PaddleOCR\n",
    "import cv2\n",
    "\n",
    "# 创建 PaddleOCR 实例，设置使用简体中文\n",
    "ocr = PaddleOCR(use_angle_cls=True, lang='ch')  # lang='ch' 表示使用中文\n",
    "\n",
    "# 加载图像\n",
    "image_path = r'D:\\test\\Pic.png'\n",
    "image = cv2.imread(image_path)\n",
    "\n",
    "# 使用 PaddleOCR 进行文本识别\n",
    "result = ocr.ocr(image_path, cls=True)\n",
    "\n",
    "# 打印识别结果\n",
    "for line in result:\n",
    "    for word_info in line:\n",
    "        print(word_info[1][0])  # 提取并打印文本内容\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "12568b55",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python [conda env:py37]",
   "language": "python",
   "name": "conda-env-py37-py"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.12"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
